home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 026a / miltime.zip / MILTIME.UDF
Text File  |  1991-07-04  |  2KB  |  44 lines

  1. From UserId Jcoc on the ATBBS.  07/01/91.
  2. Taken from message traffic on the ATBBS.
  3. Do your own testing.  No guarantees are made.
  4.  
  5. MilTime() UDF converts an H:MM AM/PM time string to HH:MM:SS 24 hour time.
  6.  
  7. FUNCTION MilTime
  8.   PARAMETER pass_time
  9.   PRIVATE pass_time,t_str,rvalue,hr_loc,hr_time
  10.   t_str=TRIM(LOWER(pass_time))  && convert A to a and P to p
  11.   DO CASE
  12.     CASE AT('a',t_str)<>0  && is 12-hour time and AM
  13.       rvalue=SUBSTR(t_str,1,AT('a',t_str)-1)
  14.       IF val(rvalue)<10.and.AT('0',rvalue)<>1  && add leading zero if necessary
  15.         rvalue='0'+rvalue  && add a leading zero
  16.       ENDIF
  17.       * check for 12:00 AM to 12:59 AM.  should be 00:nn in 24 hr time
  18.       IF rvalue='12'
  19.         rvalue='00'+SUBSTR(rvalue,3)
  20.       ENDIF
  21.     CASE AT('p',t_str)<>0  && is 12-hour time and PM
  22.       rvalue=SUBSTR(t_str,1,AT('p',t_str)-1)
  23.       hr_loc=AT(':',t_str)
  24.       IF hr_loc<>0  && if a valid time string
  25.         hr_time=VAL(SUBS(t_str,1,hr_loc-1))
  26.         * check for 01:00 PM to 11:59 PM.  add 12 hours for 24 hr time
  27.         IF hr_time<12
  28.           hr_time=hr_time+12
  29.         ENDIF
  30.         hr_time=LTRIM(STR(hr_time))
  31.         rvalue=hr_time+SUBSTR(rvalue,hr_loc)
  32.       ELSE
  33.         ?? chr(7)  && invalid time was passed
  34.         rvalue='**:**'
  35.       ENDIF
  36.     OTHERWISE && if already 24-hour time
  37.       rvalue=t_str
  38.       * add leading zero if necessary
  39.       IF VAL(rvalue)<10.and.AT('0',rvalue)<>1
  40.         rvalue='0'+rvalue
  41.       ENDIF
  42.   ENDCASE
  43. RETURN(TRIM(rvalue))
  44.